﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Index.Master" Inherits="System.Web.Mvc.ViewPage<Langben.DAL.ts_billin>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    损溢单
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
     <div id="divQuery"  title="查询列表" class="easyui-dialog" closed="true" modal="false"
        iconcls="icon-search" style=" width:500px;">
        <table width="90%">
           <tr style="line-height:30px">
           <td width="100px">日期</td>
           <td width="170px"><input type='text' id='tbStart' style="width:170px" class="easyui-datebox"/></td>
           <td width="10px" align="left">到</td>
           <td width="170px"><input type='text' id='tbEnd' style="width:170px" class="easyui-datebox"/></td>
           </tr>
            <tr>
           <td>单号</td>
           <td colspan="3"><input type='text' id='tbDH'/></td> 
           </tr> 
           <tr> 
           <td>原始单号</td>
           <td colspan="3"><input type='text' id='tbYSDH'/></td> 
           </tr> 
           </table>
    </div> 
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">

    <script type="text/javascript" language="javascript">
        $(function () {

            $('#flexigridData').datagrid({
                title: '损溢单', //列表的标题
                iconCls: 'icon-site',
                width: 'auto',
                height: 'auto',
                nowrap: false,
                striped: true,
                singleSelect: true,
                collapsible: true,
                url: '../ts_billin/GetDataSY', //获取数据的url
                sortName: 'Id',
                sortOrder: 'desc',
                idField: 'Id',

                toolbar: [
                    {
                        text: '查询',
                        iconCls: 'icon-search',
                        handler: function () {
                            flexiQuery();
                        }
                    }, {
                        text: '开单',
                        iconCls: 'icon-add',
                        handler: function () {
                            return flexiCreate();
                        }
                    },
                //                     {
                //                        text: '删除',
                //                        iconCls: 'icon-remove',
                //                        handler: function () {
                //                            return flexiDelete();
                //                        }
                //                    }, 
                    {
                    text: '查看',
                    iconCls: 'icon-edit',
                    handler: function () {
                        return flexiModify();
                    }
                     }],
                columns: [[

                    { field: 'i_sign', title: '<%: Html.LabelFor(model => model.i_sign) %>', width: 61 }
                    , { field: 'i_no', title: '<%: Html.LabelFor(model => model.i_no) %>', width: 61 }
					, { field: 'c_type', title: '<%: Html.LabelFor(model => model.c_type) %>', width: 61 }
					, { field: 'dt_dt', title: '<%: Html.LabelFor(model => model.dt_dt) %>', width: 80
                    , formatter: function (value, rec) {
                        if (value) {
                            return dateConvert(value);
                        }
                    }
					}
					, { field: 'c_base', title: '<%: Html.LabelFor(model => model.c_base) %>', width: 90 }
					, { field: 'c_id', title: '<%: Html.LabelFor(model => model.c_id) %>', width: 61 }
					, { field: 'c_orgno', title: '<%: Html.LabelFor(model => model.c_orgno) %>', width: 61 }
					, { field: 'c_agency', title: '<%: Html.LabelFor(model => model.c_agency) %>', width: 61 }
					, { field: 'c_keeper', title: '<%: Html.LabelFor(model => model.c_keeper) %>', width: 61 }
					, { field: 'c_clerk', title: '<%: Html.LabelFor(model => model.c_clerk) %>', width: 61 }
					, { field: 'c_audi', title: '<%: Html.LabelFor(model => model.c_audi) %>', width: 61 }
					, { field: 'c_comment', title: '<%: Html.LabelFor(model => model.c_comment) %>', width: 100 }

                ]],
                pagination: true,
                rownumbers: true

            });

            var parent = window.dialogArguments; //获取父页面
            if (parent == "undefined" || parent == null) {
                //    不是在iframe中打开的
            } else {
                //隐藏所有的按钮和分隔符
                $(".l-btn.l-btn-plain").hide();
                $(".datagrid-btn-separator").hide();
                //添加选择按钮
                $('#flexigridData').datagrid("addToolbarItem", [{ "text": "选择", "iconCls": "icon-ok", handler: function () { flexiSelect(); } }]);
            }
        });

        //“查询”按钮，弹出查询框
        function flexiQuery() {
            $('#divQuery').dialog({
                buttons: [{
                    text: '查询',
                    iconCls: 'icon-ok',
                    handler: function () {
                        //将查询条件按照分隔符拼接成字符串
                        var search = "";
                        search += "tbStart" + "&" + $('#tbStart').datebox('getValue') + "^";
                        search += "tbEnd" + "&" + $('#tbEnd').datebox('getValue') + "^";
                        search += "tbDH" + "&" + $('#tbDH').val() + "^";
                        search += "tbYSDH" + "&" + $('#tbYSDH').val() + "^";

                        //                        $('#divQuery').find(":text,:selected,select,textarea,:hidden,:checked,:password").each(function () {
                        //                            search = search + this.id + "&" + this.value + "^";
                        //                        });
                        //执行查询                        
                        $('#flexigridData').datagrid('reload', { search: search });
                    }
                },
                     {
                         text: '取消',
                         iconCls: 'icon-cancel',
                         handler: function () {
                             $('#divQuery').dialog("close");
                         }
                     }]
            });
            $('#divQuery').dialog("open");
            //将查询条件按照分隔符拼接成字符串           

        };

        //“选择”按钮，在其他（与此页面有关联）的页面中，此页面以弹出框的形式出现，选择页面中的数据
        function flexiSelect() {

            var rows = $('#flexigridData').datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }

            var arr = [];
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].Id);
            }
            arr.push("^");
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].c_type);
            }
            //主键列和显示列之间用 ^ 分割   每一项用 , 分割
            if (arr.length > 0) {//一条数据和多于一条
                returnParent(arr.join("&")); //每一项用 & 分割
            }
        }
        //导航到查看详细的按钮
        function getView() {

            var arr = $('#flexigridData').datagrid('getSelections');

            if (arr.length == 1) {
                window.location.href = "../ts_billin/Details/" + arr[0].Id;

            } else {
                $.messager.alert('操作提示', '请选择一条数据!', 'warning');
            }
            return false;
        }
        //导航到创建的按钮
        function flexiCreate() {

            window.location.href = "../ts_billin/CreateSY";
            return false;
        }
        //导航到修改的按钮
        function flexiModify() {

            var arr = $('#flexigridData').datagrid('getSelections');

            if (arr.length == 1) {
                window.location.href = "../ts_billin/EditSY/" + arr[0].Id;

            } else {
                $.messager.alert('操作提示', '请选择一条数据!', 'warning');
            }
            return false;

        };
        //删除的按钮
        function flexiDelete() {

            var rows = $('#flexigridData').datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }

            var arr = [];
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].Id);
            }

            $.messager.confirm('操作提示', "确认删除这 " + arr.length + " 项吗？", function (r) {
                if (r) {
                    $.post("../ts_billin/Delete", { query: arr.join(",") }, function (res) {
                        if (res == "OK") {
                            //移除删除的数据

                            $.messager.alert('操作提示', '删除成功!', 'info');
                            $("#flexigridData").datagrid("reload");
                            $("#flexigridData").datagrid("clearSelections");
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');
                            }
                        }
                    });
                }
            });

        };

    </script>

</asp:Content>
